import os
import time
import sys
from pymongo import MongoClient


class tradeDB:
	def __init__(self):
		self.client = MongoClient('mongodb://127.0.0.1:8016/')
		#self.client = MongoClient('mongodb://127.0.0.1:9016/')
		self.db = self.client['AItrade']
		print ("[DB info]: AItrade database is connected!!")

	def createDatabase(self):
		collection = self.db['mycollection']
		data = {
		       'name': 'Alice',
		       'age': 25,
		       'city': 'New York'
		       }
		result = collection.insert_one(data)
		print(f"Inserted document ID: {result.inserted_id}")

	def dropDatabase(self):
		self.client.drop_database('AItrade')
		self.client.close()
		print ("[DB info]: AItrade database has been drop!!")


	def query_data_sample(self):
		collection = self.db['mycollection']
		documents = collection.find()# 打印查询结果
		for document in documents:
			print(document)

	def insert_stock_data():
		pass

	def update_stock_data():
		pass

	def delete_stock_data():
		pass


mydb = tradeDB()
# mydb.query_data_sample()

# if __name__ == '__main__':
# 	mydb = tradeDB()
# 	mydb.createDatabase()
